<template>
  <div>
    <el-button type="danger" @click="add">添加</el-button>
    <!-- 全部打开：default-expand-all -->
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="title" label="活动名称"></el-table-column>
      <el-table-column prop="begintime" label="开始时间" width="200px">
        <template slot-scope="scope">{{scope.row.begintime|toTime}}</template>
      </el-table-column>
      <el-table-column prop="endtime" label="结束时间" width="200px">
        <template slot-scope="scope">{{scope.row.endtime|toTime}}</template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==1" type="success" size="medium">已启用</el-tag>
          <el-tag v-else type="danger" size="medium">已禁用</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            size="mini"
            @click="edit(scope.row)"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            size="mini"
            @click="del(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="popType+'秒杀'" :visible.sync="dialogVisible" width="45%">
      <seckill-info :transData="transData" :popType="popType"></seckill-info>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="dialogVisible = false">取 消</el-button>
        <el-button type="danger" size="medium" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import seckillInfo from "./info";
import moment from 'moment';
import { getSeckillList ,getCateList} from "../../request";
export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      popType: "新增",
      transData: []
    };
  },
  components: {
    seckillInfo
  },
  created() {
    // 获取秒杀列表
    this.getData();
  },
  methods: {
    //获取会员列表
    async getData() {
      let res = await getSeckillList();
      this.tableData = res;
    },
    add() {
      this.popType = "新增";
      this.transData = {
        title: "",
        begintime: "",
        value1: [],
        endtime: "",
        first_cateid: "",
        second_cateid: "",
        goodsid: "",
        status: 1
      };
      this.dialogVisible = true;
    },
    async edit(data) {
        this.popType = "修改";
        this.transData=data;
        // console.log(moment(parseInt(data.begintime)).format('YYYY-MM-DD HH:MM:SS'))
        // Date.parse(data.begintime.replace(/-/g, '/'))
        // this.transData.value1=[(moment(parseInt(data.begintime))).format('YYYY-MM-DD HH:mm:ss'),moment(parseInt(data.endtime)).format('YYYY-MM-DD HH:mm:ss')]
        // let arr=[(moment(parseInt(data.begintime))).format('YYYY-MM-DD HH:mm:ss'),moment(parseInt(data.endtime)).format('YYYY-MM-DD HH:mm:ss')]
        this.$set(this.transData,'value1',[(moment(parseInt(data.begintime))).format('YYYY-MM-DD HH:mm:ss'),moment(parseInt(data.endtime)).format('YYYY-MM-DD HH:mm:ss')])
        // console.log(this.transData);
        
        this.dialogVisible = true;
    },
    del(id) {
        this.$confirm("确认删除吗,是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          confirmButtonClass: "el-button--danger"
        })
          .then(res => {
            this.doDel(id);
          })
          .catch(_ => {});
    },
    doDel(id) {
        this.$http.post("/seckdelete", { id }).then(res => {
          this.tableData = res.data.list;
        });
    }
  }
};
</script>
<style lang="" >
.el-button {
  margin-bottom: 10px;
}
.el-pagination__total {
  float: right;
}
.el-tag {
  margin-left: 3px;
}
</style>